/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * V2.java
 *
 * Created on 14-may-2012, 12:44:46
 */
package practtica4;

import BBDD.GestorBBDD;
import MetodosAuxiliares.MetAux;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author usuario_local
 */
public class V2 extends javax.swing.JFrame {

    /** Creates new form V2 */
    MetAux metAux=new MetAux();
    GestorBBDD gestor= new GestorBBDD();
    
    
    public V2() throws ClassNotFoundException, SQLException {
        initComponents();
        campoTitulo.setText(Integer.toString(gestor.numDoc()));
        campoTitulo.setEditable(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        campoTitulo = new javax.swing.JTextField();
        botonAceptar = new javax.swing.JButton();
        campoRuta = new javax.swing.JTextField();
        campoPalClave = new javax.swing.JTextField();
        campoDescripcion = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        botonExaminar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel3.setText("Palabras clave");

        jLabel4.setText("Ruta");

        campoTitulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoTituloActionPerformed(evt);
            }
        });

        botonAceptar.setText("Aceptar");
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        campoPalClave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                campoPalClaveActionPerformed(evt);
            }
        });

        jLabel2.setText("Descripción");

        jLabel1.setText("Título");

        botonExaminar.setText("Examinar...");
        botonExaminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonExaminarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(56, 56, 56)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(campoRuta)
                    .addComponent(campoPalClave)
                    .addComponent(campoDescripcion)
                    .addComponent(campoTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonExaminar)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(288, Short.MAX_VALUE)
                .addComponent(botonAceptar)
                .addGap(41, 41, 41))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(campoTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(campoDescripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(48, 48, 48)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(campoPalClave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(campoRuta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(botonExaminar)))
                .addGap(27, 27, 27)
                .addComponent(botonAceptar)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void campoTituloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoTituloActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_campoTituloActionPerformed

private void campoPalClaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_campoPalClaveActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_campoPalClaveActionPerformed

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        // TODO add your handling code here:
        
        int titulo=Integer.parseInt(campoTitulo.getText());
        if(campoTitulo.getText().isEmpty()){
            JOptionPane.showMessageDialog(this, "Rellenar campo Titulo, sólo con números");
        }
        String desc= campoDescripcion.getText();
        if(desc.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Descripción");
        String palClave=campoPalClave.getText();
        if(palClave.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Palabras Clave");
        String ruta=campoRuta.getText();
        if(ruta.isEmpty())
            JOptionPane.showMessageDialog(this, "Rellenar campo Ruta");
        try {
            gestor.anyadirDocumento(titulo);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(V2.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(V2.class.getName()).log(Level.SEVERE, null, ex);
        }
        V3 v3=new V3(titulo);
        v3.setVisible(true);
        this.dispose();
        
    }//GEN-LAST:event_botonAceptarActionPerformed

    private void botonExaminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonExaminarActionPerformed
            JFileChooser selecFich = new JFileChooser();	//origen
            selecFich.showOpenDialog(null);
            String fuente=selecFich.getSelectedFile().getAbsolutePath();
            campoRuta.setText(fuente);
    }//GEN-LAST:event_botonExaminarActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JButton botonExaminar;
    private javax.swing.JTextField campoDescripcion;
    private javax.swing.JTextField campoPalClave;
    private javax.swing.JTextField campoRuta;
    private javax.swing.JTextField campoTitulo;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables
}
